/*     */ package com.umeng.fb.model;
/*     */ 
/*     */ import android.content.Context;
/*     */ import android.os.Handler;
/*     */ import android.os.Message;
/*     */ import com.umeng.fb.c.a;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Collections;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ import java.util.Set;
/*     */ import java.util.concurrent.ConcurrentHashMap;
/*     */ import java.util.concurrent.ExecutorService;
/*     */ import java.util.concurrent.Executors;
/*     */ import org.json.JSONArray;
/*     */ import org.json.JSONException;
/*     */ import org.json.JSONObject;
/*     */ 
/*     */ public class Conversation
/*     */ {
/*  28 */   private static final String b = Conversation.class.getName();
/*     */   private Context c;
/*  31 */   private static ExecutorService d = Executors.newSingleThreadExecutor();
/*     */   private String e;
/*     */   private String f;
/*  39 */   List<Reply> a = new ArrayList();
/*     */   private String g;
/*     */   private Map<String, Reply> h;
/*     */ 
/*     */   public synchronized List<Reply> getReplyList()
/*     */   {
/*  48 */     this.a.clear();
/*  49 */     this.a.addAll(this.h.values());
/*  50 */     Collections.sort(this.a);
/*  51 */     return this.a;
/*     */   }
/*     */ 
/*     */   public Conversation(Context paramContext)
/*     */   {
/*  58 */     this.c = paramContext;
/*  59 */     this.g = com.umeng.common.b.q(this.c);
/*  60 */     this.e = a.a(this.c);
/*  61 */     this.f = com.umeng.common.b.h(this.c);
/*     */ 
/*  63 */     this.h = new ConcurrentHashMap();
/*     */   }
/*     */ 
/*     */   Conversation(String paramString, JSONArray paramJSONArray, Context paramContext)
/*     */     throws JSONException
/*     */   {
/*  76 */     this.c = paramContext;
/*  77 */     this.g = com.umeng.common.b.q(this.c);
/*  78 */     this.e = paramString;
/*  79 */     this.f = com.umeng.common.b.h(this.c);
/*     */ 
/*  82 */     this.h = new HashMap();
/*     */ 
/*  87 */     if ((paramJSONArray == null) || (paramJSONArray.length() < 1)) {
/*  88 */       return;
/*     */     }
/*     */ 
/*  93 */     for (int i = 0; i < paramJSONArray.length(); i++) {
/*  94 */       JSONObject localJSONObject = paramJSONArray.getJSONObject(i);
/*  95 */       String str = localJSONObject.getString("type");
/*  96 */       Object localObject = null;
/*  97 */       if (Reply.TYPE.NEW_FEEDBACK.toString().equals(str))
/*  98 */         localObject = new UserTitleReply(localJSONObject);
/*  99 */       else if (Reply.TYPE.USER_REPLY.toString().equals(str))
/* 100 */         localObject = new UserReply(localJSONObject);
/* 101 */       else if (Reply.TYPE.DEV_REPLY.toString().equals(str)) {
/* 102 */         localObject = new DevReply(localJSONObject);
/*     */       }
/* 104 */       if (localObject == null) {
/* 105 */         throw new JSONException(
/* 106 */           "Failed to create Conversation using given JSONArray: " + 
/* 107 */           paramJSONArray + " at element " + i + ": " + localJSONObject);
/*     */       }
/* 109 */       if (!this.h.containsKey(((Reply)localObject).c)) {
/* 110 */         this.h.put(((Reply)localObject).c, localObject);
/*     */       }
/*     */     }
/* 113 */     b();
/*     */   }
/*     */ 
/*     */   public void addUserReply(String paramString)
/*     */   {
/*     */     Object localObject;
/* 125 */     if (this.h.size() < 1)
/* 126 */       localObject = new UserTitleReply(paramString, this.g, this.f, this.e);
/*     */     else {
/* 128 */       localObject = new UserReply(paramString, this.g, this.f, this.e);
/*     */     }
/* 130 */     if (!this.h.containsKey(((Reply)localObject).c)) {
/* 131 */       this.h.put(((Reply)localObject).c, localObject);
/*     */     }
/*     */ 
/* 134 */     b();
/*     */   }
/*     */ 
/*     */   private void b()
/*     */   {
/* 141 */     Store.getInstance(this.c).saveCoversation(this);
/*     */   }
/*     */ 
/*     */   JSONArray a() {
/* 145 */     JSONArray localJSONArray = new JSONArray();
/* 146 */     for (Map.Entry localEntry : this.h.entrySet())
/*     */     {
/* 148 */       Reply localReply = (Reply)localEntry.getValue();
/* 149 */       localJSONArray.put(localReply.toJson());
/*     */     }
/* 151 */     return localJSONArray;
/*     */   }
/*     */ 
/*     */   public String getId() {
/* 155 */     return this.e;
/*     */   }
/*     */ 
/*     */   public void sync(SyncListener paramSyncListener)
/*     */   {
/* 169 */     final SyncHandler localSyncHandler = new SyncHandler(paramSyncListener);
/* 170 */     Runnable local1 = new Runnable()
/*     */     {
/*     */       public void run() {
/* 173 */         ArrayList localArrayList1 = new ArrayList();
/* 174 */         ArrayList localArrayList2 = new ArrayList();
/* 175 */         Date localDate = null;
/* 176 */         String str = "";
/*     */ 
/* 183 */         for (Object localObject2 = Conversation.a(Conversation.this).entrySet().iterator(); ((Iterator)localObject2).hasNext(); ) { localObject1 = (Map.Entry)((Iterator)localObject2).next();
/* 184 */           Reply localReply = (Reply)((Map.Entry)localObject1).getValue();
/* 185 */           if (((localReply instanceof UserReply)) || 
/* 186 */             ((localReply instanceof UserTitleReply))) {
/* 187 */             if (localReply.i == Reply.STATUS.NOT_SENT)
/* 188 */               localArrayList1.add(localReply);
/*     */           }
/* 190 */           else if (((localReply instanceof DevReply)) && (
/* 191 */             (localDate == null) || 
/* 192 */             (localDate.compareTo(localReply.getDatetime()) < 0))) {
/* 193 */             localDate = localReply.getDatetime();
/* 194 */             str = localReply.c;
/*     */           }
/*     */ 
/*     */         }
/*     */ 
/* 201 */         localArrayList2.add(Conversation.c(Conversation.this));
/*     */ 
/* 203 */         for (localObject2 = localArrayList1.iterator(); ((Iterator)localObject2).hasNext(); ) { localObject1 = (Reply)((Iterator)localObject2).next();
/* 204 */           boolean bool = new com.umeng.fb.a.b(Conversation.d(Conversation.this)).a((Reply)localObject1);
/* 205 */           if (bool)
/*     */           {
/* 211 */             Message localMessage = Message.obtain();
/* 212 */             localMessage.what = 2;
/* 213 */             localMessage.obj = localObject1;
/* 214 */             localMessage.arg1 = (bool ? 1 : 0);
/* 215 */             localSyncHandler.sendMessage(localMessage);
/*     */           }
/*     */         }
/*     */ 
/* 219 */         Object localObject1 = new com.umeng.fb.a.b(Conversation.d(Conversation.this))
/* 220 */           .a(localArrayList2, str, Conversation.e(Conversation.this));
/*     */ 
/* 222 */         localObject2 = Message.obtain();
/* 223 */         ((Message)localObject2).what = 1;
/* 224 */         Conversation.MessageWrapper localMessageWrapper = new Conversation.MessageWrapper();
/* 225 */         localMessageWrapper.b = ((List)localObject1);
/* 226 */         localMessageWrapper.a = localArrayList1;
/* 227 */         ((Message)localObject2).obj = localMessageWrapper;
/*     */ 
/* 229 */         localSyncHandler.sendMessage((Message)localObject2);
/*     */       }
/*     */     };
/* 233 */     d.execute(local1);
/*     */   }
/*     */ 
/*     */   static class MessageWrapper
/*     */   {
/*     */     List<Reply> a;
/*     */     List<DevReply> b;
/*     */   }
/*     */ 
/*     */   class SyncHandler extends Handler
/*     */   {
/*     */     Conversation.SyncListener a;
/*     */     static final int b = 1;
/*     */     static final int c = 2;
/*     */ 
/*     */     public SyncHandler(Conversation.SyncListener arg2)
/*     */     {
/*     */       Object localObject;
/* 244 */       this.a = localObject;
/*     */     }
/*     */ 
/*     */     public void handleMessage(Message paramMessage)
/*     */     {
/*     */       Object localObject;
/* 255 */       if (paramMessage.what == 2) {
/* 256 */         localObject = (Reply)paramMessage.obj;
/* 257 */         int i = paramMessage.arg1 == 1 ? 1 : 0;
/* 258 */         if (i != 0)
/* 259 */           ((Reply)localObject).i = Reply.STATUS.SENT;
/*     */       }
/* 261 */       else if (paramMessage.what == 1) {
/* 262 */         localObject = (Conversation.MessageWrapper)paramMessage.obj;
/* 263 */         List localList1 = ((Conversation.MessageWrapper)localObject).b;
/* 264 */         List localList2 = ((Conversation.MessageWrapper)localObject).a;
/*     */ 
/* 266 */         if (localList1 != null)
/*     */         {
/* 269 */           Iterator localIterator = localList1.iterator();
/* 270 */           while (localIterator.hasNext()) {
/* 271 */             Reply localReply = (Reply)localIterator.next();
/* 272 */             if (Conversation.a(Conversation.this).containsKey(localReply.c)) {
/* 273 */               localIterator.remove();
/*     */             }
/*     */             else
/*     */             {
/* 277 */               Conversation.a(Conversation.this).put(localReply.c, localReply);
/*     */             }
/*     */           }
/*     */         }
/*     */ 
/* 282 */         Conversation.b(Conversation.this);
/* 283 */         if (this.a != null) {
/* 284 */           this.a.onReceiveDevReply(localList1);
/* 285 */           this.a.onSendUserReply(localList2);
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   public static abstract interface SyncListener
/*     */   {
/*     */     public abstract void onReceiveDevReply(List<DevReply> paramList);
/*     */ 
/*     */     public abstract void onSendUserReply(List<Reply> paramList);
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\umeng_sdk.jar
 * Qualified Name:     com.umeng.fb.model.Conversation
 * JD-Core Version:    0.6.2
 */